package live.jialing.sip.base.domain;

import com.fasterxml.jackson.annotation.JsonIdentityInfo;
import com.fasterxml.jackson.annotation.ObjectIdGenerators;
import com.google.common.collect.Lists;
import live.jialing.core.beanvalidator.First;
import live.jialing.core.beanvalidator.Second;
import live.jialing.sip.base.dict.SchoolCategoryEnum;
import live.jialing.structure.domain.Company;
import lombok.Getter;
import lombok.Setter;
import lombok.ToString;

import javax.persistence.*;
import javax.validation.constraints.NotNull;
import java.util.List;

/**
 * 学校
 */
@Setter
@Getter
@ToString
@Entity
@DiscriminatorValue("school")
@JsonIdentityInfo(generator = ObjectIdGenerators.PropertyGenerator.class, property = "id",scope = School.class)
public class School extends Company {

    /**
     * 学校类别
     */
    @NotNull(message = "学校类别不能为空", groups = {First.class, Second.class})
    @Enumerated(EnumType.STRING)
    private SchoolCategoryEnum category;//学校类别

    /**
     * 年级组
     */
    @OneToMany(mappedBy = "school", fetch = FetchType.LAZY)
    private List<GradeGroup> gradeGroups = Lists.newArrayList();

    /**
     * 班
     */
    @OneToMany(mappedBy = "school", fetch = FetchType.LAZY)
    private List<Squad> classes = Lists.newArrayList();

    /**
     * 学生
     */
    @OneToMany(mappedBy = "school", fetch = FetchType.LAZY)
    private List<Student> students = Lists.newArrayList();

}
